// import { WEBSOCKET_EVENT_TYPES } from '~/helpers/constants'

interface DBModels {
  token: string
}
export type ListenerType = 'set' | 'delete'
type Listener<K extends keyof DBModels> = (t: ListenerType, v?: DBModels[K]) => void
type DBData = {
  [K in keyof DBModels]: Array<Listener<K>>
}
const datas: Partial<DBData> = {}

export const addListener = <K extends keyof DBModels>(key: K, fn: Listener<K>) => {
  const arr: Listener<K>[] = (datas[key] as Listener<K>[]) || []
  arr.push(fn)
  datas[key] = arr as Partial<DBData>[K]
}

export const removeListener = <K extends keyof DBModels>(key: K, fn: Listener<K>) => {
  if (datas[key]) {
    const i = (datas[key] as Listener<K>[])?.indexOf(fn) || -1
    if (i >= 0) {
      datas[key]?.splice(i, 1)
    }
  }
}
export interface ApiResponse<T> {
  data: T
  code: number
  message: string
  success: boolean
}

// export type WebSocketEventTypes = (typeof WEBSOCKET_EVENT_TYPES)[number]

export interface WebSocketEventData {
  event: WebSocketEventTypes
  data: any
}

export interface WebSocketData {

  /**
   * 系统公告
   */
  get_system_notice: boolean

  /**
   * 最新下注
   */
  get_game_bet_recent: Array<any>

  /**
   * 豪客赛最新下注
   */
  get_hks_recent: Array<any>

  /**
   * 最新胜利
   */
  get_win_recent: Array<any>

  /**
   * 获取通知列表
   */
  get_big_win_recent: Array<any>

  /**
   * 异地登录
   */
  other_places_login: number

  /**
   * 是否有新消息
   */
  new_user_message: number

  /**
   * 余额更新
   */
  update_money: object
}
